﻿
// 2023/2/28: 首个版本
// 2023/7/12: CompatibleChannelData和CompatibleImage的默认构造函数生成无效对象

#ifndef COMPATIBLE_IMAGE_H_
#define COMPATIBLE_IMAGE_H_

#include "spadas.h"
#include "NextOpenCV.h"

namespace videonext
{
	using namespace spadas;

	enum class CompatibleImageType
	{
		None = 0,
		ImagePointerColor = 1, // 1 channel, BGR
		ImagePointerGray = 2, // 1 channel, Mono
		IplImageGray = 10, // 1 channel, Mono
		IplImageColor = 11, // 1 channel, BGR
		AVFrameYUV420P = 20, // 3 channels, Y, U, V
		AVFrameNV12 = 21, // 2 channels, Y, UV
		AVFrameYUV422P = 22, // 3 channels, Y, U, V
		CompatibleChannelGray = 30, // 1 channel, Mono
	};

	class CompatibleChannelData : public Object<class CompatibleChannelDataVars>
	{
	public:
		CompatibleChannelData();
		CompatibleChannelData(class CompatibleImage owner, UInt width, UInt height, UInt step, UInt bbp, Byte *data);

		UInt width();
		UInt height();
		UInt step();
		UInt bbp(); // bytes per pixel
		Byte *data();

#if defined(VIDEONEXT_WITH_OPENCV)
		Bool iplImage(IplImage& ipl); // no copy
#endif
		ImagePointer imagePtr(); // copy
	};

	class CompatibleImage : public Object<class CompatibleImageVars>
	{
	public:
		CompatibleImage();
		CompatibleImage(CompatibleImageVars *v);
		CompatibleImage(CompatibleImageType type, Size2D size); // type None/CompatibleChannelGray unsupported
		CompatibleImage(ImagePointer imagePtr);
#if defined(VIDEONEXT_WITH_OPENCV)
		CompatibleImage(IplImage *iplImage, Bool own);
#endif
		CompatibleImage(Pointer avFrame, Bool own);
		CompatibleImage(CompatibleChannelData channel); // bbp=1 only

		CompatibleImageType getType();
		Pointer getImage();

		UInt width();
		UInt height();
		Size2D size();
		Array<CompatibleChannelData> channels();
	};
}

#endif
